<script type="text/javascript">
//初始化完成
$('#pool_available_tb').jqGrid({
    url: '/pool/grid',
    datatype: 'json',
    mtype: 'GET',
    colNames: ['编号', '[["label path"|translate]]', '容量', "协议类型", '卷数量', '[["label quota"|translate]](G)',
        "[['replication number'|translate]]","纠删码","精简配置", '端口数', '连接数', '快照属性', "[['PROTECTION DOMAINS'|translate ]]", '分层',
        "[['label owner'|translate]]", "[['label Creation time'|translate]]", "[['label operation'|translate]]"
    ],
    colModel: [{
        name: 'id',
        index: 'id',
        width: 2,
        align: 'left',
        hidden: true
    }, {
        name: 'name',
        index: 'name',
        width: 5,
        align: 'left',
        formatter: function(cellvalue, option, row) {
            var outerWidth = $('#pool_available_tb_name').width() - 20;
            return '<a style="display:inline-block;text-overflow:ellipsis; white-space:nowrap;overflow:hidden;width:' + outerWidth + 'px;" href="#" onclick="detail_open(\'' + option.gid + '\',\'' + option.rowId + '\')">' + cellvalue + '</a>';
        },
        unformat: jqUnformat,
    }, {
        name: '容量',
        index: '容量',
        width: 5,
        align: 'left',
        sortable: false,
        hidden: true
    }, {
        name: 'protocol',
        index: 'protocol',
        width: 5,
        align: 'left',
        sortable: false,
        formatter: function(cellvalue, option, row) {
            var protocol = cellvalue.toUpperCase();
            if (protocol == 'ISCSI'){
                protocol = "iSCSI";
            }
            return protocol
        },
        unformat: jqUnformat,
    }, {
        name: 'volume_num',
        index: 'volume_num',
        width: 5,
        align: 'left'
    }, {
        name: 'quota',
        index: 'quota',
        width: 3,
        align: 'left'
    }, {
        name: 'repnum',
        index: 'repnum',
        width: 5,
        align: 'left'
    },
    {
        name:'ec', 
        index:'ec', 
        width:5, 
        lign:'left',
        hidden: true
    },
    {
        name: 'porvinsioning',
        index: 'porvinsioning',
        width: 5,
        align: 'left',
        formatter: function(cellvalue, option, row) {
            return SelfTranslate(cellvalue)
        },
        unformat: function(cellvalue) {
            return cellvalue;
        }
    },
    {
        name: 'port_num',
        index: 'port_num',
        width: 5,
        align: 'left',
        hidden: true
    }, {
        name: 'link_num',
        index: 'link_num',
        width: 5,
        align: 'left',
        hidden: true,
        sortable: false
    }, {
        name: 'snapshot',
        index: 'snapshot',
        width: 5,
        align: 'left',
        hidden: true
    }, {
        name: 'protection_domain',
        index: 'protection_domain',
        width: 3,
        align: 'left'
    }, {
        name: 'priority_',
        index: 'priority_',
        width: 6,
        align: 'left'
    }, {
        name: 'username',
        index: 'username',
        width: 5,
        align: 'left'
    }, {
        name: 'created_at',
        index: 'created_at',
        width: 7,
        align: 'left'
    }, {
        name: 'service',
        index: 'service',
        width: 13,
        align: 'left',
        hidden: false,
        detailHidden: true,
        formatter: function(cell, option, row) {
            var html = '';
            row = row2object(row, option.gid); 
            var protocol = row['protocol']
            if (protocol != 'nfs'){
                html += '<button title="创建卷" class="btn btn-blue" onclick="create_volume_with_pool(' + row['id'] + ')">创建卷</button>';
            }
            html += '<button style="margin-left:10px;" title="编辑" class="btn btn-blue" onclick="pool_update(' + row['id'] + ')">编辑</button>';
            html += '<button style="margin-left:10px;" title="删除" class="btn btn-blue" onclick=pool_delete_confirm(' + row['id'] + ',"' + row['name'] + '")>删除</button>';
            return html;
        }
    }],
    page: 1,
    rowNum: 10,
    sortname: 'id',
    sortorder: 'desc',
    viewrecords: true,
    multiselect: false,
    multiboxonly:true,
    multiselectWidth:'60px',
    altclass: 'ui-priority-secondary',
    altRows: true,
    autowidth: true,
    beforeSelectRow:function(rowid, e) {
        if($(e.target).is('input')) {
            return true;
        }
        return false;
    },
    gridComplete: function() {
        var gridData = $(this).jqGrid('getRowData');
        jqgrid_page($(this), gridData);
        jqgrid_resize($(this));
    }
});

function create_volume_with_pool(pool_id) {
    angular.element('#volume_controller').scope().open("/volume/create?pool_id=" + pool_id);
    
}
function pool_update(pool_id) {
    angular.element('#pool_create_button').scope().open("/pool/update?pool_id=" + pool_id);
}

function pool_delete(pool_id) {
    $.get('/pool/delete', {
            'id': pool_id
        },
        function(data) {
            if (data.reply.is_success) {
                $("#pool_available_tb").trigger("reloadGrid");
            } else {
                error = data.reply.error;
                SelfAlert(error);
            }
        });
    $('#tb_event_mng').trigger("reloadGrid");
}

function pool_delete_confirm(pool_id, pool_name) {
    msg = '确定删除（' + pool_name + '）？';
    SelfConfirm(msg, pool_delete, pool_id, "删除提示");
}
//daiwenxue-update
$("#pool_create_button").click(function() {
    angular.element('#pool_create_button').scope().open("/pool/create");
});
$("#show_all").click(function() {
    var records = $('#pool_available_tb').getGridParam("records");
    $('#pool_available_tb').jqGrid('setGridParam', {
        rowNum: records + 100
    }).trigger("reloadGrid");
});
</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div class="title-tag">
            <h3>资源池</h3>
            <p>资源池</p>
        </div>
        <div class="grid-tools">
            <div class="grid-operate pull-left">
                <button id="volume_controller" ng-controller="VolumeModalCtrl" ng-show="false"></button>
                <button class="btn btn-blue" type="button" id="pool_create_button" ng-controller="PoolModalCtrl">创建</button>
                <!-- <button class="btn btn-blue" type="button" id="pool_delete_button">删除</button> -->
            </div>
        </div>
        <div id="grid_pool_available" class='grid-body'>
            <table id="pool_available_tb"></table>
        </div>
    </div>
</div>
